package com.dobbinsoft.iotechn.apigw.mq.config;

import com.dobbinsoft.iotechn.apigw.mq.DataPointInnerMessageListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.listener.PatternTopic;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;

/**
 * Description: 内部MQ
 * User: rize
 * Date: 2020/6/27
 * Time: 15:53
 */
@Configuration
public class RedisMQConfig {

    @Autowired
    private LettuceConnectionFactory defaultLettuceConnectionFactory;

    @Bean
    public DataPointInnerMessageListener dataPointMessageListener() {
        return new DataPointInnerMessageListener();
    }

    @Bean
    public RedisMessageListenerContainer redisMessageListenerContainer(DataPointInnerMessageListener dataPointMessageListener) {
        RedisMessageListenerContainer container = new RedisMessageListenerContainer();
        container.setConnectionFactory(defaultLettuceConnectionFactory);
        /**
         * 添加订阅者监听类，数量不限.PatternTopic定义监听主题,这里监听dj主题
         */
        container.addMessageListener(dataPointMessageListener, new PatternTopic("API_GW"));
        return container;

    }

}
